package com.game.modular.game.act.cultivate;

import com.game.comment.core.ResponseResult;
import com.game.comment.util.JwtUtils;
import com.game.modular.game.act.cultivate.vo.CultivateVo;
import com.game.modular.game.playerAssets.domain.PlayerBag;
import com.game.modular.game.playerAssets.service.PlayerBagServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;


/**
 * 背包物品(PlayerBag)表服务控制层
 *
 * @author cxy
 * @since 2024-07-26 17:49:04
 */
@Api(tags = "玩家物品")
@Validated
@RestController
@AllArgsConstructor
@RequestMapping("/playerBagAct")
public class PlayerBagAction {
    @Resource
    private PlayerBagServiceImpl accountBagService;

    @ApiOperation("玩家背包信息")
    @PostMapping("/list")
    public ResponseResult<List<PlayerBag>> list(@RequestHeader String token) {
        return ResponseResult.success(accountBagService.eqlist(
                PlayerBag.builder().uid(JwtUtils.getPlayerId(token)).build()
        ));
    }

    @ApiOperation("玩家使用道具(按coreId使用)")
    @PostMapping("/use")
    public ResponseResult<PlayerBag> use(
            @RequestHeader String token,
            @Valid @RequestBody CultivateVo.PlayerBagVo.use pram
    ) {
        return ResponseResult.success(accountBagService.use(
                JwtUtils.getPlayerId(token),
                pram.getId(),
                pram.getNum()
        ));
    }
}
